<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\ResourceCollection;

class CelueCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return [
          'code'=>200,
          'message'=>'请求数据成功',
          'data'=>$this->collection->map(function ($item){
              /**
               * @var $item \App\Models\Celue
               */
              return [
                'id'=>$item->id,
                'title'=>$item->title,
                'jianjie'=>$item->jianjie,
                'logo'=>$item->logo ? \Storage::url($item->logo) :'',
                  'view_num'=>$item->view_num,
                  'created_at'=>Carbon::parse($item->created_at)->format('Y-m-d H:i:s'),
              ];
          })
        ];
    }
}
